package GUI;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.border.TitledBorder;
import javax.swing.text.MaskFormatter;
import javax.swing.JLabel;
import java.awt.Font;
import java.text.ParseException;

import javax.swing.JFormattedTextField;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.JComboBox;
import javax.swing.JButton;
import javax.swing.DefaultComboBoxModel;

import Classes.Professor;
import Repositorio.Rep_Professor;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.Window.Type;
import javax.swing.JPasswordField;

public class CadProfessor extends JFrame {

	private JPanel contentPane;
	private JTextField txtNomeProf;
	private JTextField txtCpfProf;
	private JTextField txtAno;
	private JTextField txtEndereco;
	private JTextField txtEmail;
	private JTextField txtTelefone;
	private JPasswordField tpassSenha;
	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					CadProfessor frame = new CadProfessor();
					frame.setLocationRelativeTo(null);
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 * @throws ParseException 
	 */
	public CadProfessor() throws ParseException 
	{
	
		JOptionPane.setRootFrame(this);
		setResizable(false);
		setAlwaysOnTop(true);
		setResizable(false);
		setType(Type.NORMAL);
		setTitle("Cadastro de Professor");
		setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		setBounds(100, 100, 619, 422);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		JPanel panel = new JPanel();
		panel.setBounds(5, 5, 600, 378);
		panel.setLayout(null);
		contentPane.add(panel);
		
		JPanel panel_1 = new JPanel();
		panel_1.setLayout(null);
		panel_1.setBorder(new TitledBorder(null, "", TitledBorder.LEADING, TitledBorder.TOP, null, null));
		panel_1.setBounds(10, 11, 582, 59);
		panel.add(panel_1);
		
		JLabel lblCadastroDeProfessor = new JLabel("Cadastro de Professor");
		lblCadastroDeProfessor.setFont(new Font("Tahoma", Font.PLAIN, 22));
		lblCadastroDeProfessor.setBounds(186, 15, 222, 33);
		panel_1.add(lblCadastroDeProfessor);
		
		JPanel panel_2 = new JPanel();
		panel_2.setLayout(null);
		panel_2.setBorder(new TitledBorder(null, "", TitledBorder.LEADING, TitledBorder.TOP, null, null));
		panel_2.setBounds(10, 81, 582, 248);
		panel.add(panel_2);
		
		txtNomeProf = new JTextField();
		txtNomeProf.setColumns(10);
		txtNomeProf.setBounds(88, 15, 484, 20);
		panel_2.add(txtNomeProf);
		
		MaskFormatter mskcpf = new MaskFormatter("###.###.###-##");
		txtCpfProf = new JFormattedTextField(mskcpf);
		txtCpfProf.setColumns(10);
		txtCpfProf.setBounds(88, 46, 484, 20);
		panel_2.add(txtCpfProf);
		
		MaskFormatter xtAno_Conclusao = new MaskFormatter("####");
		txtAno = new JFormattedTextField(xtAno_Conclusao);
		txtAno.setColumns(10);
		txtAno.setBounds(438, 204, 134, 20);
		panel_2.add(txtAno);
		
		JLabel label_1 = new JLabel("Nome");
		label_1.setBounds(10, 18, 46, 14);
		panel_2.add(label_1);
		
		JLabel label_3 = new JLabel("CPF");
		label_3.setBounds(10, 49, 46, 14);
		panel_2.add(label_3);
		
		JLabel lblAno = new JLabel("Ano Conclusao Mestrado");
		lblAno.setBounds(308, 207, 120, 14);
		panel_2.add(lblAno);
		
		final JComboBox cmbTituloGrad = new JComboBox();
		cmbTituloGrad.setModel(new DefaultComboBoxModel(new String[] {"Ciencias", "Filosofia", "Direito"}));
		cmbTituloGrad.setSelectedIndex(0);
		cmbTituloGrad.setToolTipText("");
		cmbTituloGrad.setBounds(88, 173, 210, 20);
		panel_2.add(cmbTituloGrad);
		
		JLabel lblTitGrad = new JLabel("Tit. Grad.");
		lblTitGrad.setBounds(10, 176, 46, 14);
		panel_2.add(lblTitGrad);
		
		JLabel lblTitMestrado = new JLabel("Tit. Mestrado");
		lblTitMestrado.setBounds(10, 207, 68, 14);
		panel_2.add(lblTitMestrado);
		
		final JComboBox cmbTituloMest = new JComboBox();
		cmbTituloMest.setModel(new DefaultComboBoxModel(new String[] {"Doutorado\t", "Mestrado", "Pos-Grad"}));
		cmbTituloMest.setSelectedIndex(0);
		cmbTituloMest.setBounds(88, 204, 210, 20);
		panel_2.add(cmbTituloMest);
		
		JLabel lblEndereco = new JLabel("Endereco");
		lblEndereco.setBounds(10, 80, 68, 14);
		panel_2.add(lblEndereco);
		
		txtEndereco = new JTextField();
		txtEndereco.setColumns(10);
		txtEndereco.setBounds(88, 77, 484, 20);
		panel_2.add(txtEndereco);
		
		JLabel lblEmail = new JLabel("E-mail");
		lblEmail.setBounds(10, 113, 46, 14);
		panel_2.add(lblEmail);
		
		txtEmail = new JTextField();
		txtEmail.setBounds(87, 107, 211, 20);
		panel_2.add(txtEmail);
		txtEmail.setColumns(10);
		
		JLabel lblTelefone = new JLabel("Telefone");
		lblTelefone.setBounds(10, 142, 46, 14);
		panel_2.add(lblTelefone);
		
		MaskFormatter msktel = new MaskFormatter("(##)####-####");
		txtTelefone = new JFormattedTextField(msktel);
		txtTelefone.setBounds(87, 138, 211, 20);
		panel_2.add(txtTelefone);
		txtTelefone.setColumns(10);
		
		JLabel lblSenha = new JLabel("Senha:");
		lblSenha.setBounds(329, 113, 46, 14);
		panel_2.add(lblSenha);
		
		tpassSenha = new JPasswordField();
		tpassSenha.setBounds(385, 110, 187, 20);
		panel_2.add(tpassSenha);
		
		JButton button = new JButton("Salvar");
		button.addActionListener(new ActionListener() {
			@SuppressWarnings("deprecation")
			public void actionPerformed(ActionEvent arg0) 
			{
				Professor prof = new Professor();
				Rep_Professor rep_prof = new Rep_Professor();
				
				prof.setNome(txtNomeProf.getText());
				prof.setCpf(txtCpfProf.getText());
				prof.setTitulo_grad(cmbTituloGrad.getSelectedItem().toString());
				prof.setTitulo_mest(cmbTituloMest.getSelectedItem().toString());
				prof.setAno_conclusao_mest(txtAno.getText());
				prof.setEndereco(txtEndereco.getText());
				prof.setTelefone(txtTelefone.getText());
				prof.setEmail(txtEmail.getText());
				prof.setSenha(tpassSenha.getText());
				
				rep_prof.InserirProfessorDB(prof);
				
			}
		});
		button.setBounds(10, 340, 136, 32);
		panel.add(button);
		
		JButton button_1 = new JButton("Cancelar");
		button_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) 
			{
				dispose();
			}
		});
		button_1.setBounds(450, 340, 142, 32);
		panel.add(button_1);
	}
}
